<?php
//角色
namespace app\adminbackstage\model;

use think\facade\Db;
use think\Model;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class Role extends Model{
    protected $pk = 'uid';
    // 模型初始化
    protected static function init()
    {
        parent::init();
        //TODO:初始化内容
    }
    
    //
    public function find($where){
        $list = $this::name('role')

            ->field('r.id as r_id ,r.name,m.id as m_id,m.rid as m_rid,m.mid as m_mid,m.r_read,m.r_writ,me.id as meid ,me.superior_id as superior_id ,me.menu_name as menu_name,me.link as link,me.Icon as Icon,me.exhibition as exhibition')
            ->alias('r')
            ->leftJoin('role_menu as m','m.rid = r.id')
            ->leftjoin('menu as  me','me.id = m.mid')
            ->where($where)
            ->order('r.id', 'desc')

            ->find();
        return $find;
    }

    
    public function listRole($where,$page=1,$num=10){
        $list = $this::name('role')
        ->where($where)
        ->limit(($page-1)*$num,$num)
        ->select();
        return $list;
    }
    
    public function countRole($where) {
        return $count = $this::name('role')
        ->where($where)
        ->count();
    }
    
//    public function countUser($where) {
//        $list = $this::name('user')
//        ->field('u.*,m.m_id')
//        ->alias('u')
//        ->leftJoin('pg_user_member m','u.uid = m.uid')
//        ->where($where)
//        ->order('u.uid', 'desc')
//        ->paginate();
//        $count = $list->total();
//        return $count;
//    }
//    
    
    //角色添加
    public  function roleAdd(array $data){
        return self::create($data);
    }
    
    //角色信息变更
    public function roleEdit($id,$update){
        $in = $this::update($update, ['id' => $id]);
        return $in;
    }


}
